#define _CRT_SECURE_NO_WARNINGS 1

public:
    int takeAttendance(vector<int>& records)
    {
        int left = 0;
        int right = records.size() - 1;
        int mid = 0;



        while (left < right)
        {
            mid = left + (right - left) / 2;

            if (mid == records[mid])
            {
                left = mid + 1;
            }
            else
            {
                right = mid;
            }
        }

        if (records[left] == left)return  records[left] + 1;
        return records[left] - 1;
    }
};